package theOrbalEra.common.item;

import java.util.List;

import theOrbalEra.common.util.DefultValue;
import theOrbalEra.common.util.GetName;

import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class OrbalItemEleBag extends OrbalItem {
	public OrbalItemEleBag(int itemID) {
		super(itemID);
		this.setMaxStackSize(1);
		

	}
	

	@Override
	public void onUpdate(ItemStack par1ItemStack, World par2World,Entity par3Entity, int par4, boolean par5) {
		EntityPlayer player=(EntityPlayer)par3Entity;
		
		
			for(int i=0;i<player.inventory.mainInventory.length;i++){
				ItemStack stack=player.inventory.mainInventory[i];
				if(stack!=null)
				if(stack.getItem() instanceof OrbalItemEleBag){
				//PLAN delete a bag
				}
				
				
			}
	
		
		super.onUpdate(par1ItemStack, par2World, par3Entity, par4, par5);
	}


	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	@SideOnly(Side.CLIENT)
	public void addInformation(ItemStack par1ItemStack,
			EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
		int[] ele=OrbalItemEleBag.getEleCount(par1ItemStack);
		par3List.add(GetName.localize("ele.fire")+":" + ele[0]);
		par3List.add(GetName.localize("ele.water")+":" + ele[1]);
		par3List.add(GetName.localize("ele.earth")+":" + ele[2]);
		par3List.add(GetName.localize("ele.wind")+":" + ele[3]);
		par3List.add(GetName.localize("ele.time")+":" + ele[4]);
		par3List.add(GetName.localize("ele.space")+":" + ele[5]);
		par3List.add(GetName.localize("ele.unreal")+":" + ele[6]);
		super.addInformation(par1ItemStack, par2EntityPlayer, par3List, par4);
	}
	 /**
	 * @param par1ItemStack
	 * @return
	 */
	public static int[] getEleCount(ItemStack par1ItemStack)
	    {
		 int[] eleCount={0,0,0,0,0,0,0};
	        NBTTagCompound var1 = par1ItemStack.getTagCompound();

	        if (var1 == null)
	        {
	            return eleCount;
	        }
	        else
	        {
	            NBTTagCompound var2 = var1.getCompoundTag("eleBag");
	            if(var2==null)
	            	return eleCount;
	            else if(var2.hasKey("count")){
	            	return var2.getIntArray("count");
	            }
	            else
	            	return eleCount;
	            }
	    }
	 
	    /**
	     * @param par1ItemStack
	     * @param par2 0=fire,1=water,2=earth,3=wind,4=time,5=space,6=unreal
	     */
	    public static void setEleCount(ItemStack par1ItemStack, int[] par2)
	    {
	        NBTTagCompound var1 = par1ItemStack.getTagCompound();

	        if (var1 == null)
	        {
	            var1 = new NBTTagCompound();
	            par1ItemStack.setTagCompound(var1);
	        }

	        NBTTagCompound var2 = var1.getCompoundTag("eleBag");

	        if (!var1.hasKey("eleBag"))
	        {
	            var1.setCompoundTag("eleBag", var2);
	        }

	        
	            var2.setIntArray("count", par2);
	        
	    }
	    
	    @Override
		@SideOnly(Side.CLIENT)
		public void registerIcons(IconRegister par1IconRegister) {
			this.itemIcon=par1IconRegister.registerIcon(DefultValue.ModName+":ele_bag");
			}


		public static boolean hasbag(EntityPlayer player) {
			ItemStack[] main=player.inventory.mainInventory;
			for(ItemStack stack:main){
				if(stack!=null&&stack.getItem() instanceof OrbalItemEleBag)
					return true;
			}
			return false;
		}
		
		public static int getBaginInv(EntityPlayer player){
			int pos=-1;
			ItemStack[] main=player.inventory.mainInventory;
			for(int i=0;i<main.length;i++){
				if(main[i]!=null&&main[i].getItem() instanceof OrbalItemEleBag){
					pos= i;
					break;
				}
				
			}
			
			return pos;
		}

	

	

}
